// pages/classification/index.js
import { http } from '../../utils/net.js'
Page({

  /**
   * 页面的初始数据
   */
  // tab切换
  data: {
    // 页面配置  
    winWidth: 0,
    winHeight: 0,
    // tab切换
    currentTab: 0,
    // 交易市场
    page1: 1,
    size1: 100,
    count1: -1,
    finish1:false,
    marketList: [],

    // 我的交易
    page2: 1,
    size2: 100,
    count2: -1,
    finish2: false,
    mySellList: []
  },

  // 滑动切换tab

  bindChange: function (e) {
    var that = this;
    that.setData({ currentTab: e.detail.current });
  },
  // 点击tab切换
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  getMarketData() {
    http({
      url: "/api/index/index?method=sell_card_list",
      data: {
        page: this.data.page1,
        size: this.data.size1
      },
      isShowLoading: true,
      success: (res) => {
        // TODO
        this.setData({
          marketList: res.data.data,
          count1: res.data.count1,
          finish1: true
        })
      }
    })
  },
  getMySellData() {
    http({
      url: "/api/index/index?method=my_sell_card",
      data: {
        page: this.data.page2,
        size: this.data.size2
      },
      isShowLoading: true,
      success: (res) => {
        // TODO
        this.setData({
          mySellList: res.data.data,
          count2: res.data.count1,
          finish2: true
        })
      }
    })
  },
  onShow: function () {
    this.getMarketData()
    this.getMySellData()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})